# Maintainer: Sébastien Luttringer <seblu@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

pkgname=patch
pkgver=2.7.6
pkgrel=3
pkgdesc='A utility to apply patch files to original sources'
arch=('x86_64')
url='https://www.gnu.org/software/patch/'
license=('GPL')
groups=('base-devel')
depends=('glibc' 'attr')
makedepends=('ed')
optdepends=('ed: for patch -e functionality')
validpgpkeys=('259B3792B3D6D319212CC4DCD5BF9FEB0313653A') # Andreas Gruenbacher
source=("https://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.xz"{,.sig}
        "https://github.com/mirror/patch/commit/f290f48a621867084884bfff87f8093c15195e6a.patch" # CVE-2018-6951
        "CVE-2018-1000156.patch" # CVE-2018-1000156
        "https://github.com/mirror/patch/commit/9c986353e420ead6e706262bf204d6e03322c300.patch" # CVE-2018-6952
        "http://git.savannah.gnu.org/cgit/patch.git/patch/?id=19599883ffb6a450d2884f081f8ecf68edbed7ee" # Fix memory leaks introduced in CVE-2018-1000165
        "http://git.savannah.gnu.org/cgit/patch.git/patch/?id=369dcccdfa6336e5a873d6d63705cfbe04c55727"
        )
md5sums=('78ad9937e4caadcba1526ef1853730d5'
         'SKIP'
         '7e34fc859ccc07b235a8b01b043ff456'
         'fb16655d092f251316715e792636b48d'
         'aa8ac1e3dccbd523143b01e9f60b06e8'
         'bba3e65611813a4467cdd73219a5059d'
         '5eb2c88e30fa8775deaf0b29287bf6bd')

prepare() {
  cd $pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      echo "Applying patch ${filename##*/}"
      patch -p1 -N -i "$srcdir/${filename##*/}"
    fi
  done
  :
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr
  make
}

check() {
  cd $pkgname-$pkgver
  make check
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
}

# vim:set ts=2 sw=2 et:
